home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tptc16.zip / DIA.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  8KB  |  304 lines

  1.  
  2. (*
  3.  * hardware diagnostic utility
  4.  * s.h.smith, 13-jan-87
  5.  *
  6.  * has analog driver for rev-b analog.  otherwise generic.
  7.  *
  8.  *)
  9.  
  10.  
  11. {$c-}
  12.  
  13. type
  14.    anystring = string[80];
  15.  
  16. var
  17.    hardware:  char;
  18.  
  19.  
  20. function digit(i: integer): char;
  21. begin
  22.    i := i and 15;
  23.    if i > 9 then i := i + 7;
  24.    digit := chr(i + ord('0'));
  25. end;
  26.  
  27. function itoh(i: integer): anystring;
  28. begin
  29.    itoh := {digit(i shr 12) + digit(i shr 8) + }digit(i shr 4) + digit(i);
  30. end;
  31.  
  32.  
  33. function itob(i: integer): anystring;
  34. const
  35.    bits: array[0..15] of anystring =
  36.       ('0000','0001','0010','0011',
  37.        '0100','0101','0110','0111',
  38.        '1000','1001','1010','1011',
  39.        '1100','1101','1110','1111');
  40. begin
  41.    itob := bits[(i shr 4) and 15] + bits[i and 15];
  42. end;
  43.  
  44.  
  45. function htoi(h:anystring): integer;
  46. var
  47.    i,j: integer;
  48. begin
  49.    j := 0;
  50.    for i := 1 to length(h) do
  51.       j := j * 16 + pos(upcase(h[i]),'123456789ABCDEF');
  52.    htoi := j;
  53. end;
  54.  
  55.  
  56. procedure determine_hardware;
  57. begin
  58.    port[$342] := 6;
  59.    case port[$342] and 7 of
  60.       1:    hardware := 'B';
  61.       7,0:  hardware := 'A';
  62.       else
  63.          writeln('Warning: possible unknown hardware: ',port[$342]);
  64.          hardware := 'B';
  65.    end;
  66.  
  67.    writeln('hardware: rev ',hardware);
  68. end;
  69.  
  70.  
  71. procedure readanalog;
  72. var
  73.    h,l: integer;
  74.    s:   anystring;
  75.    d:   char;
  76.  
  77. begin
  78.    write('display data (y/n/b)? ');
  79.    read(kbd,s[1]);
  80.    d := upcase(s[1]);
  81.  
  82.    while not keypressed do
  83.    begin
  84.       port[$341] := 0;   {start conversion};
  85.       repeat
  86.         l := port[$342];
  87.       until ((l and $80) = 0) or keypressed;
  88.  
  89.       l := port[$340];
  90.       h := port[$341];
  91.  
  92.       case d of
  93.          'Y': write(itoh(h),itoh(l),'    ');
  94.          'B': write(itob(h),itob(l),'    ');
  95.       end;
  96.    end;
  97. end;
  98.  
  99.  
  100. procedure readport;
  101. var
  102.    p: integer;
  103.    s: anystring;
  104.    d: integer;
  105.  
  106. begin
  107.    write('read what port(hex): ');
  108.    readln(s);
  109.    p := htoi(s);
  110.  
  111.    write('display data(y/n/b)? ');
  112.    read(kbd,s[1]);
  113.  
  114.    writeln('reading from port $',itoh(hi(p)), itoh(lo(p)));
  115.  
  116.    if upcase(s[1]) = 'Y' then
  117.    while not keypressed do
  118.       write(itoh(port[p]),'  ')
  119.    else
  120.  
  121.    if upcase(s[1]) = 'B' then
  122.    while not keypressed do
  123.       write(itob(port[p]),'  ')
  124.  
  125.    else
  126.       while not keypressed do
  127.          d := port[p];
  128. end;
  129.  
  130.  
  131. procedure writetest;
  132. var
  133.    p: integer;
  134.    d: integer;
  135.    d2:integer;
  136.    s: anystring;
  137.  
  138. begin
  139.    write('write what port(hex): ');
  140.    readln(s);
  141.    p := htoi(s);
  142.  
  143.    write('write what data(hex): ');
  144.    readln(s);
  145.    d := htoi(s);
  146.  
  147.    writeln('writing data $',itoh(lo(d)),
  148.            ' to port $',itoh(hi(p)), itoh(lo(p)));
  149.  
  150.    while not keypressed do
  151.       port[p] := d;
  152. end;
  153.  
  154.  
  155.  
  156. procedure writetoggle;
  157. var
  158.    p: integer;
  159.    d: integer;
  160.    d1: integer;
  161.    s: anystring;
  162.    v: integer;
  163.  
  164. begin
  165.    write('write toggle to what port(hex): ');
  166.    readln(s);
  167.    p := htoi(s);
  168.  
  169.    write('toggle from bits(hex): ');
  170.    read(s);
  171.    d := htoi(s);
  172.  
  173.    write('   to bits(hex): ');
  174.    readln(s);
  175.    d1 := htoi(s);
  176.  
  177.    writeln('toggle data between $',itoh(d),' and $',itoh(d1),
  178.            ' to port $',itoh(hi(p)), itoh(lo(p)));
  179.  
  180.    while not keypressed do
  181.    for v := 1 to 5 do
  182.    begin
  183.       port[p] := d;
  184.       port[p] := d1;
  185.    end;
  186. end;
  187.  
  188.  
  189. procedure setmux;
  190. var
  191.    m: integer;
  192. begin
  193.    write('what mux channel 0..7: ');
  194.    readln(m);
  195.    port[$342] := m;
  196. end;
  197.  
  198.  
  199. procedure pause;
  200. begin
  201.    writeln;
  202.    write('press <enter> to continue');
  203.    readln;
  204.    writeln;
  205. end;
  206.  
  207. procedure map_ports;
  208. begin
  209.       writeln;
  210.       writeln('I/O port information for PC Consoles');
  211.       writeln;
  212.       writeln('   DMC400_base_address = $3EE;');
  213.       writeln('   MOTION_data_port = $3EE;');
  214.       writeln('   MOTION_stat_port = $3EF;');
  215.       writeln;
  216.       writeln('   DASH8_base_address = $340;');
  217.       writeln('   DASH8_data_lo      = $340;   {low data register}');
  218.       writeln('   DASH8_data_hi      = $341;   {high data register}');
  219.       writeln('   DASH8_start_cmd    = $341;   {start-conversion by writing to this port}');
  220.       writeln('   DASH8_op_port      = $342;   {parallel output}');
  221.       writeln('      ANALOG_mux_bits = $07;         {multiplex select bits}');
  222.       writeln('      old_ANALOG_power_supply_enable_bit = $80;');
  223.       writeln('   DASH8_ip_port      = $342;   {parallel input}');
  224.       writeln('      hardware_version_mask = $7;');
  225.       writeln('      ANALOG_end_conversion = $80;   {low when conversion is finished}');
  226.  
  227.       pause;
  228.       writeln('   CTM05_base_address = $300;  {switches set (0=on) to 11000000}');
  229.       writeln('   CTM05_data_port    = $300;  {counter data read/write port}');
  230.       writeln('   CTM05_cmd_port     = $301;  {counter command/status port}');
  231.       writeln('   CTM05_ip_port      = $302;  {parallel input port}');
  232.       writeln('      COUNTERS_calib_status      = $01;    {also runs waterdraw valve}');
  233.       writeln('      COUNTERS_meter_status      = $02;');
  234.       writeln('      valve_return_closed_status = $04;    {active low}');
  235.       writeln('      valve_return_open_status   = $08;    {active low}');
  236.       writeln('      calib_count_overflow       = $10;');
  237.       writeln('      calib_timer_overflow       = $20;');
  238.       writeln('      meter_count_overflow       = $40;');
  239.       writeln('      meter_timer_overflow       = $80;');
  240.       pause;
  241.       writeln('   CTM05_op_port      = $303;  {parallel output port}');
  242.       writeln('      COUNTERS_ee_mode_disable   = $01;    {hi for always count, lo for normal}');
  243.       writeln('      COUNTERS_reset_bit         = $02;    {resets everything when low,');
  244.       writeln('                                            including ee flop,');
  245.       writeln('                                            hi for normal operation}');
  246.       writeln('      COUNTERS_ee_init           = $10;    {toggle low to initialize ee');
  247.       writeln('                                            circuit (only before stroke!)');
  248.       writeln('                                            hi for normal operation}');
  249.       writeln('      COUNTERS_motor_enable      = $08;    {hi to enable motor');
  250.       writeln('                                            lo to disable}');
  251.       writeln('      valve_return_close_bit     = $40;    {0=on 1=off}');
  252.       writeln('      valve_return_open_bit      = $80;    { "      " }');
  253.       writeln('      old_calib_gate = $01;');
  254.       writeln('      old_meter_gate = $02;');
  255.       writeln('      old_reset_bits = $0C;');
  256.       pause;
  257.       writeln('   CTM05_2_base_address = $3A0;    {switches set (0=on) to 11101000}');
  258.       writeln('   CTM05_2_data_port    = $3A0;    {counter data read/write port}');
  259.       writeln('   CTM05_2_cmd_port     = $3A1;    {counter command/status port}');
  260.       writeln('   CTM05_2_ip_port      = $3A2;    {parallel input port}');
  261.       writeln('      COUNTERS_isolation_valve_status_bit  = $04;   {0=inline, 1=isolated}');
  262.       writeln('      COUNTERS_power_switch_status_bit     = $08;   {1=on, 0=off (switch on');
  263.       writeln('                                                     operator''s panel)}');
  264.       writeln('   CTM05_2_op_port      = $3A3;    {parallel output port}');
  265.       writeln('      COUNTERS_d_allow            = $01;  {hi to allow counters to run,');
  266.       writeln('                                           lo to stop counters}');
  267.       writeln('      COUNTERS_power_enable_bit   = $02;  {1=on 0=off}');
  268.       writeln;
  269. end;
  270.  
  271. var
  272.    cmd: anystring;
  273.  
  274. begin
  275.  textbackground(0);
  276.  clrscr;
  277.  
  278.  repeat
  279.    writeln;
  280.    writeln('pc console hardware diagnostic 14-jan-87 (30-apr-87)');
  281.    determine_hardware;
  282.  
  283.    writeln;
  284.    write('read, write, toggle, analog, mux, ?=map (r/w/t/a/m/?/q)? ');
  285.    read(kbd,cmd[1]);
  286.    writeln(cmd[1]);
  287.  
  288.    case upcase(cmd[1]) of
  289.       'R':  readport;
  290.       'W':  writetest;
  291.       'T':  writetoggle;
  292.       'A':  readanalog;
  293.       'M':  setmux;
  294.       'Q':  halt;
  295.       '?':  map_ports;
  296.    end;
  297.  
  298.    if keypressed then
  299.       read(kbd,cmd[1]);
  300.  
  301.  until true=false;
  302. end.
  303.  
  304.